package cn.command

import cn.wetcland.pojo.WetclandPlayer

class T {
     var test : String = ""
        get() = "123"
        set(value){field = value}

}

class Mime {
    // size属性
    private val size = 0

    // 即isEmpty这个属性，是判断该类的size属性是否等于0
    val isEmpty : Boolean
        get() = this.size == 0

    // 另一个例子
    val num = 2
        get() = if (field > 5) 10 else 0

}

class Person {

    var name: String = "zhang"
        //get() = field.toUpperCase()   // 将变量赋值后转换为大写
        set(value) {field = value}
    var no: Int = 100
        set(value) {
            if (value < 10) {       // 如果传入的值小于 10 返回该值
                field = value
            } else {
                field = -1         // 如果传入的值大于等于 10 返回 -1
            }
        }

    var heiht: Float = 145.4f
        private set



}

fun f1(a: Int, b: Int): Int = a + b

fun f2(vararg list: String): Unit {
    for (v in list) {
        print("$v ")
    }
    var t: String = "template"
    println(t + "")
}

fun f3(): Unit {
    var t: Any? = null
    println(t ?: -1)
}

fun hasPrefix(x: Any) = when(x) {
    is String -> x.startsWith("prefix")
    else -> false
}

fun main(args: Array<String>) {
    println(f1(1, 2))
    f2("1", "2", "3", "4", "5", "6")
    f3()
    for (v in 5 downTo 0) {
        println(v)
    }
    val a: Int = 4_5_6
    println(a)
    val text = """
    >多行字符串
    |菜鸟教程
    |多行字符串
    |Runoob
    """.trimMargin(">")
    println(text)    // 前置空格删除了
    val v1 = 100
    val v2 = if(v1 > 0) 4 else -4
    when(v2) {
        4, -4 -> println()
        else -> {

        }
    }
    println(hasPrefix(""))
    val wetclandPlayer = WetclandPlayer()
    wetclandPlayer.qq = "123"
    println(wetclandPlayer)
    val arr = Array<Int>(4) { v -> v.dec()}
    arr[0] = 4
    for (v in arr) {
        println(v)
    }
    val person = Person()
    //person.name = "asdf"
    println(person)
    val mime = Mime()
    println("isEmpty = ${mime.isEmpty}")
    println("num = ${mime.num}")
}
